home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / cmds / fsmakedev / fsmakedev.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-09-11  |  2.4 KB  |  97 lines

  1. /* 
  2.  * fsmakedev.c --
  3.  *
  4.  *    Make a device file.
  5.  *
  6.  * Copyright (C) 1986 Regents of the University of California
  7.  * All rights reserved.
  8.  */
  9.  
  10. #ifndef lint
  11. static char rcsid[] = "$Header: /sprite/src/cmds/fsmakedev/RCS/fsmakedev.c,v 1.3 90/09/11 13:49:11 jhh Exp $ SPRITE (Berkeley)";
  12. #endif not lint
  13.  
  14. #include "sprite.h"
  15. #include "option.h"
  16. #include "fs.h"
  17. #include "kernel/fs.h"
  18. #include "stdio.h"
  19.  
  20. /*
  21.  * Constants settable via the command line.
  22.  */
  23. char *deviceName;        /* Set to "/dev/rsd0" */
  24. char    *permissionString = "0644";
  25. int serverID = -1;
  26. int deviceType = 0;
  27. int deviceUnit = 0;
  28.  
  29. Option optionArray[] = {
  30.     {OPT_STRING, "p", (Address)&permissionString,
  31.     "Permission bits in octal (default is 0644)"},
  32.     {OPT_INT, "s", (Address)&serverID,
  33.     "Server ID, (default is localhost)"},
  34.     {OPT_INT, "d", (Address)&deviceType,
  35.     "Device type, (default is 0)"},
  36.     {OPT_INT, "u", (Address)&deviceUnit,
  37.     "Device unit, (default is 0)"},
  38. };
  39. int numOptions = sizeof(optionArray) / sizeof(Option);
  40.  
  41.  
  42. /*
  43.  *----------------------------------------------------------------------
  44.  *
  45.  * main --
  46.  *
  47.  *    Creates a device file.  Each device has a serverID that
  48.  *    identfies what host has the device, a device type, and
  49.  *    a device unit number.  The serverID is -1 by default,
  50.  *    which means it is a ``generic'' device that is found
  51.  *    on the local host.
  52.  *
  53.  * Results:
  54.  *    None.
  55.  *
  56.  * Side effects:
  57.  *    Calls Fs_MakeDevice.
  58.  *
  59.  *----------------------------------------------------------------------
  60.  */
  61. main(argc, argv)
  62.     int argc;
  63.     char *argv[];
  64. {
  65.     ReturnStatus status;    /* status of system calls */
  66.     int flags = 0;
  67.     Fs_Device device;
  68.     int    permissions;
  69.     int n;
  70.  
  71.     argc = Opt_Parse(argc, argv, optionArray, numOptions, 0);
  72.  
  73.     if (argc < 2) {
  74.     fprintf(stderr, "Specify device file name.\n");
  75.     Opt_PrintUsage(argv[0], optionArray, numOptions);
  76.     exit(FAILURE);
  77.     } else {
  78.     deviceName = argv[1];
  79.     }
  80.     n = sscanf(permissionString, " %o", &permissions);
  81.     if (n != 1) {
  82.     Opt_PrintUsage(argv[0], optionArray, numOptions);
  83.     exit(FAILURE);
  84.     }
  85.     device.serverID = serverID;
  86.     device.type = deviceType;
  87.     device.unit = deviceUnit;
  88.     device.data = (ClientData)0;
  89.     status = Fs_MakeDevice(deviceName, &device, permissions);
  90.     if (status != SUCCESS) {
  91.     fprintf(stderr, "%s \"%s\" <%x,%x,%x>:", argv[0], deviceName,
  92.                   device.serverID, device.type, device.unit);
  93.     Stat_PrintMsg(status, "");
  94.     }
  95.     exit(status);
  96. }
  97.